package com.admin.scroller.photoorvideo.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;

import com.admin.scroller.photoorvideo.beans.LocalPhoto;
import com.admin.scroller.photoorvideo.holders.ChildGridHolder;

import java.util.List;

/**
 * 列表展示fragment的列表适配器
 * 的 每一item 的 grid 适配器
 */
public class GridViewAdapter extends RecyclerView.Adapter<ChildGridHolder>{

    private Context context;
    private List<LocalPhoto> photoList;
    private ChildGridHolder.OnImageItemClick onImageItemClick;
    private int pIndex;

    public GridViewAdapter (Context context,List<LocalPhoto> photoList,int pIndex){
        this.context=context;
        this.photoList=photoList;
        this.pIndex=pIndex;
    }

    public void setOnImageItemClick(ChildGridHolder.OnImageItemClick onImageItemClick) {
        this.onImageItemClick = onImageItemClick;
    }

    @NonNull
    @Override
    public ChildGridHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ChildGridHolder holder=ChildGridHolder.getHolder(context,parent,viewType);
        holder.setImageItemClick(onImageItemClick);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ChildGridHolder holder, int position) {
        holder.initData(photoList.get(position),position,pIndex);
    }

    @Override
    public int getItemCount() {
        return photoList==null?0:photoList.size();
    }
}
